package com.aiyige.im.model.viewHolder;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.arouter.Router;
import com.aiyige.im.model.CustomMsgData;
import com.aiyige.im.model.attachment.UserAttachment;
import com.aiyige.utils.GlideUtil;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;

public class MsgViewHolderUser extends MsgViewHolderBase {
    private ImageView ivHead;
    private TextView tvName;
    private TextView tvOther;

    private UserAttachment msgAttachment;

    public MsgViewHolderUser(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int getContentResId() {
        return R.layout.nim_item_user_content;
    }

    @Override
    protected void inflateContentView() {
        ivHead = (ImageView) view.findViewById(R.id.nim_iv_head);
        tvName = (TextView) view.findViewById(R.id.nim_tv_name);
        tvOther = (TextView) view.findViewById(R.id.nim_tv_other);
    }

    @Override
    protected void bindContentView() {
        msgAttachment = (UserAttachment) message.getAttachment();
        CustomMsgData data = msgAttachment.getKeyData();
        if (data != null) {
            GlideUtil.with(context).loadAvatar(data.getImage()).into(ivHead);
            tvName.setText(data.getTitle());
            tvOther.setText(data.getSubtitle());
        }
    }

    @Override
    protected void onItemClick() {
        msgAttachment = (UserAttachment) message.getAttachment();
        CustomMsgData data = msgAttachment.getKeyData();
        if (data != null && !TextUtils.isEmpty(data.getRouter())) {
            Router.start(data.getRouter());
        }
    }

    @Override
    protected int leftBackground() {
        return R.drawable.item_custom_msg_selector;
    }

    @Override
    protected int rightBackground() {
        return R.drawable.item_custom_msg_selector;
    }
}